import * as Koa from 'koa';
import getConnection from '../mysql/connection';
import { generateSql } from './sql';

export async function getConfigValues(ctx: Koa.Context, params?: Object)  {
  let connection: any = null;
  try {
    const db = ctx.dbPool;
    connection = await getConnection(db);
    const sql = generateSql("applet_config", "query", params);
    if (!sql) return { msg: "生成sql语句错误", success: false };
    const [result] = await connection.execute(sql);
    return { success: true, data: result };
  } catch (error) {
    return { msg: error.sqlMessage || "", success: false };
  } finally {
    if (connection) connection.release();
  }
}
